/*
ID:luongho3
LANG:JAVA
TASK:wissqu
 */
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Stack;


public class wissqu {

	char[][] map = new char[5][5];
	int[][] free = new int[5][5];
	int[] n = new int[6];
	int[] l = new int[6];
	int nPut;
	int count;
	Stack<String> stack;
	boolean first;

	public static void main(String[] args) throws Exception {
		wissqu prob = new wissqu();
		prob.read();
		prob.solve();
	}
	
	public void read() throws Exception {
		Scanner scanner = new Scanner(new File("wissqu.in"));
		String str;
		int j = 1;
		while (scanner.hasNext()) {
			str = scanner.next();
			for (int i=1;i<=4;++i) {
				map[j][i] = str.charAt(i-1);
				free[j][i] = 1;
				int idx = map[j][i] - 'A' + 1;
				n[idx]++;
				l[idx] = n[idx];
			}
			l[3] = n[3] - 1;
			l[4] = n[4] + 1;
			++j;
		}
	}
	
	public void solve() throws Exception {
		PrintStream ps = new PrintStream(new File("wissqu.out"));
		System.setOut(ps);
		nPut = 0;
		stack = new Stack<String>();
		first = true;
		count = 0;
		for (int i=1;i<=4;++i) {
			for (int j=1;j<=4;++j) {
				if (canPut(i,j,'D')) {
					nPut++;
					int idx = map[i][j] - 'A' + 1;
					l[4]--;
					n[4]++;
					n[idx]--;
					free[i][j] = 0;
					char c = map[i][j];
					map[i][j] = 'D';
					stack.push(map[i][j] + " " + i + " " + j);
					dfs();
					stack.pop();		
					map[i][j] = c;
					free[i][j] = 1;
					n[idx]++;
					n[4]--;
					l[4]++;
					nPut--;
				}
			}
		}
		System.out.println(count);
		ps.close();
	}

	private void dfs() {
		if (nPut == 16) {
			print();
			count++;
			return;
		}
		for (int i=1;i<=5;++i) {
			if (l[i] > 0) {
				if (n[i] < 4) {
					for (int j=1;j<=4;++j) {
						for (int k=1;k<=4;++k) {
							if (free[j][k] == 1) {
								char c = (char)(i + 'A' - 1);
								if (canPut(j,k,c)) {
									nPut++;
									int idx = map[j][k] - 'A' + 1;
									l[i]--;
									n[i]++;
									n[idx]--;
									free[j][k] = 0;
									char tmp = map[j][k];
									map[j][k] = c;
									stack.push(map[j][k] + " " + j + " " + k);
									dfs();
									stack.pop();
									map[j][k] = tmp;
									free[j][k] = 1;
									n[idx]++;
									n[i]--;
									l[i]++;
									nPut--;
								}
							}
						}
					}
				}
			}
		}
		
	}

	private void print() {
		if (first) {
			Stack<String> backup = new Stack<String>();
			Stack<String> output = new Stack<String>();
			while (!stack.isEmpty()) {
				output.push(stack.pop());
			}
			while (!output.isEmpty()) {
				System.out.println(output.peek());
				backup.push(output.pop());
			}
			stack = backup;
			first = false;
		}
	}

	private boolean canPut(int r, int c, char ch) {
		for (int i=-1;i<=1;++i) {
			for (int j=-1;j<=1;++j) {
				if (r + i >= 1 && r + i <= 4 && c + j >= 1 && c + j <=4) {
					if (map[r+i][c+j] == ch) {
						return false;
					}
				}
			}
		}
		return true;
	}
	
}
